package com.nage.components.touch;

import android.util.Log;

import com.nage.components.Component;
import com.nage.components.movement.Physics;
import com.nage.engine.GameObject;
import com.nage.input.Input;
import com.nage.input.InputResponder;
import com.nage.input.InputSystem;

public class Controllable extends Component implements InputResponder {

	// Used to control the physics of a game object using the user input.

	protected Physics physics;

	public Controllable(GameObject p) {
		super(p);
		type = CONTROLLABLE;
		//this.physics = physics;
		InputSystem.registerResponder(this);
	}
	
	@Override
	public boolean findLinks() {
		physics = (Physics) parent.getComponent(PHYSICS);
		return physics!=null; // if physics == null, then this will return false (ie. failure).
	}

	@Override
	public void update(long delta) {
	}

	@Override
	public void onInputEvent(Input i) {
		Log.d("Conrollable", "InputEvent detected");
		physics.addImpulse(i.xVector*5, i.yVector*5);
	}

	@Override
	public byte getOwner() {
		return parent.m_Owner;
	}

}
